/// @tags: ExLucas
#include <cstdio>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef long long LL;

constexpr int maxn = 25;

inline LL qpow(LL base, LL exp) {
  LL res = 1;
  for (; exp; exp >>= 1, base = base * base)
    if (exp & 1) res = res * base;
  return res;
}

inline LL qpow(LL base, LL exp, LL p) {
  LL res = 1;
  for (; exp; exp >>= 1, base = base * base % p)
    if (exp & 1) res = res * base % p;
  return res;
}

void exGcd(LL a, LL b, LL &x, LL &y) {
  if (b == 0) {
    x = 1, y = 0;
    return;
  }
  exGcd(b, a % b, y, x);
  y -= a / b * x;
}

inline int getInv(int a, int mod) {
  LL inv, y;
  exGcd(a, mod, inv, y);
  ((inv %= mod) += mod) %= mod;
  return inv;
}

inline LL divide(LL n, int p, int k, int pk, LL &exp) {
  if (n == 0) return 1;
  LL res = 1;
  exp += n / p;
  (res *= divide(n / p, p, k, pk, exp)) %= pk;
  LL mul = 1;
  for (int i = 1; i < pk; ++i) {
    if (i % p) (mul *= i) %= pk;
  }
  (res *= qpow(mul, n / pk, pk)) %= pk;
  for (LL i = n / pk * pk; i <= n; ++i) {
    if (i % p) (res *= (i % pk)) %= pk;
  }
  return res;
}

inline LL solve(LL n, LL m, int p, int k) {
  LL nexp = 0, mexp = 0, nmexp = 0, res = 1;
  int pk = qpow(p, k);
  res = divide(n, p, k, pk, nexp);
  (res *= getInv(divide(m, p, k, pk, mexp), pk)) %= pk;
  (res *= getInv(divide(n - m, p, k, pk, nmexp), pk)) %= pk;
  return res * qpow(p, nexp - mexp - nmexp, pk) % pk;
}

int pcnt;
int pexp[maxn], pri[maxn];

inline int main() {
  LL n, m;
  int p, _p;
  cin >> n >> m >> p;
  _p = p;
  for (int i = 2; i * i <= _p; ++i) {
    if (_p % i == 0) {
      pri[++pcnt] = i;
      while (_p % i == 0) {
        pexp[pcnt]++;
        _p /= i;
      }
    }
  }
  if (_p != 1) {
    pri[++pcnt] = _p;
    pexp[pcnt] = 1;
  }
  LL ans = 0;
  for (int i = 1; i <= pcnt; ++i) {
    int pk = qpow(pri[i], pexp[i]);
    int Mi = p / pk;
    (ans += solve(n, m, pri[i], pexp[i]) * Mi % p * getInv(Mi, pk)) %= p;
  }
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("ExLucas.in", "r", stdin);
  freopen("ExLucas.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
